<template>
    <div class="demo">
        <h2>学生名称：{{name}}</h2>
        <h2>学生年龄：{{age}}</h2>

        <button @click="sendStudentName">把学生姓名给School 组件</button>
        <hr>
    </div>
</template>

<script>
    import pubsub from 'pubsub-js';

    export default {
        name: 'Student',
        data() {
            console.log(this);
            return {
                name: '张三',
                age: 19,
            }
        },
        methods: {
            sendStudentName() {
                // 使用消息总线实现
                // this.$bus.$emit('hello',this.name)

                // 使用消息的订阅与发布实现
                pubsub.publish('hello', this.name);
            }
        },
    }
</script>

<style scoped>
    .demo {
        background-color: yellow;
    }
</style>